package com.xinxin.intelligenceexam.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.xinxin.intelligenceexam.R;
import com.xinxin.intelligenceexam.base.BaseView;
import com.xinxin.intelligenceexam.studyMenu.RunTimePermission.RuntimePermissionActivity;
import com.xinxin.intelligenceexam.studyMenu.authCodeView.AuthCodeActivity;
import com.xinxin.intelligenceexam.studyMenu.notification.NotificationActivity;
import com.xinxin.intelligenceexam.studyMenu.popMenu.PopMenuActivity;
import com.xinxin.intelligenceexam.studyMenu.recyclerView.RecyclerViewActivity;
import com.xinxin.intelligenceexam.studyMenu.recyclerViewPull.RecyclerViewPullActivity;
import com.xinxin.intelligenceexam.studyMenu.searchView.SearchViewActivity;
import com.xinxin.intelligenceexam.studyMenu.shortcut.ShortCutActivity;
import com.xinxin.intelligenceexam.studyMenu.sovleSlide.SlideActivity;
import com.xinxin.intelligenceexam.studyMenu.stepView.StepViewActivity;
import com.xinxin.intelligenceexam.studyMenu.tapToLarger.TapToLargerActivity;
import com.xinxin.intelligenceexam.studyMenu.weChatHongBao.AirActivity;
import com.xinxin.intelligenceexam.studyMenu.webH5.WebH5Activity;
import com.xinxin.intelligenceexam.utils.SnackbarUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class StudyMenuActivity extends AppCompatActivity implements BaseView {

    @BindView(R.id.lv_study_menu)
    ListView mLvStudyMenu;
    @BindView(R.id.activity_sutdy_menu)
    LinearLayout mActivitySutdyMenu;
    MyStudyMenuAdapter mMyStudyMenuAdapter;
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sutdy_menu);
        ButterKnife.bind(this);
        mContext = this;
        initView();
    }

    @Override
    public void snackBarShow(String msg) {
        SnackbarUtils.Short(mActivitySutdyMenu, msg).warning().show();
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        mMyStudyMenuAdapter = new MyStudyMenuAdapter();
        mLvStudyMenu.setAdapter(mMyStudyMenuAdapter);
        mLvStudyMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Logger.d(i);
                switch (i) {
                    case 0:
                        gotoActivity(SlideActivity.class);
                        break;
                    case 1:
                        gotoActivity(AuthCodeActivity.class);
                        break;
                    case 2:
                        gotoActivity(SearchViewActivity.class);
                        break;
                    case 3:
                        gotoActivity(StepViewActivity.class);
                        break;
                    case 4:
                        gotoActivity(RuntimePermissionActivity.class);
                        break;
                    case 5:
                        gotoActivity(RecyclerViewActivity.class);
                        break;
                    case 6:
                        gotoActivity(RecyclerViewPullActivity.class);
                        break;
                    case 7:
                        gotoActivity(PopMenuActivity.class);
                        break;
                    case 8:
                        gotoActivity(NotificationActivity.class);
                        break;
                    case 9:
                        gotoActivity(ShortCutActivity.class);
                        break;
                    case 10:
                        gotoActivity(TapToLargerActivity.class);
                        break;
                    case 11:
                        gotoActivity(WebH5Activity.class);
                        break;
                    case 12:
                        gotoActivity(AirActivity.class);
                        break;
                    case 13:
                        gotoActivity(AirActivity.class);
                        break;
                    default:
                        snackBarShow("还没有写内容");
                        break;
                }
            }
        });
    }

    public void gotoActivity(Class clazz) {
        Intent intent = new Intent(this, clazz);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    class MyStudyMenuAdapter extends BaseAdapter {
        private String[] titles;

        public MyStudyMenuAdapter() {
            titles = getResources().getStringArray(R.array.study_menu);
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Object getItem(int i) {
            return titles[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View convertView, ViewGroup viewGroup) {
            ViewHolder holder;
            if (convertView == null) {
                TextView textView = new TextView(mContext);
                textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100));
                textView.setGravity(View.TEXT_ALIGNMENT_CENTER);
                holder = new ViewHolder();
                /**得到各个控件的对象*/
                holder.title = textView;
                convertView = textView;
                convertView.setTag(holder);//绑定ViewHolder对象
            } else {
                holder = (ViewHolder) convertView.getTag();//取出ViewHolder对象
            }
            /**设置TextView显示的内容，即我们存放在动态数组中的数据*/
            holder.title.setText(titles[i]);

            return convertView;
        }
    }

    class ViewHolder {
        public TextView title;
    }
}

